# -*- coding: utf-8 -*-
# @Time : 2021/4/20 2:50 下午
# @Author : wudeyang
# @email :wudeyang@sjtu.edu.cn
# @Description:
import torch
import os
import sys

sys.path.append('./yolov5')
from yolov5 import detect
from yolov5.utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier, \
    scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path
import time
opt={'agnostic_nms':False, 'augment':False, 'classes':[2, 5, 7], 'conf_thres':0.5, 'device':'cpu', 'exist_ok':True, 'img_size':640,
     'iou_thres':0.45, 'name':'exp', 'nosave':False, 'project':'runs/detect1','save_conf':True, 'save_txt':True,
     'source':'/home/wudeyang/LPR/test_data/11.jpg', 'update':False, 'view_img':False, 'weights':'yolov5s.pt'}
check_requirements(exclude=('pycocotools', 'thop'))
start_time=time.time()
with torch.no_grad():
    # if opt['update']:  # update all models (to fix SourceChangeWarning)
    #     for opt['weights'] in ['yolov5s.pt', 'yolov5m.pt', 'yolov5l.pt', 'yolov5x.pt']:
    #         detect(opt)
    #         strip_optimizer(opt['weights'])
    # else:
    #     detect(opt)
    res=detect(opt) # 车辆检测结果
    # 车牌检测


    print(res)
print(time.time()-start_time)
